package mercadologico.dao;

import exceptions.PersistenceExceptionMessage;
import generic.dao.GenericDAO;

import java.util.ArrayList;

import javax.persistence.Query;

import mercadologico.entities.tables.Marca;

public class PersistenceMarca extends GenericDAO<Marca, Integer>{

	@Override
	public Class<Marca> getCurrentClass() {
		return Marca.class;
	}

	@SuppressWarnings("unchecked")
	public ArrayList<Marca> findByDescricaoLike(String descricao) throws PersistenceExceptionMessage {
		if (getEntityManager() != null) {
			Query query = getEntityManager().createQuery("FROM " +getCurrentClass().getName() +" c WHERE " +
					" c.descricao LIKE :descricao ORDER BY c.descricao");
		
			query.setParameter("descricao", descricao +"%");
		
			return (ArrayList<Marca>) query.getResultList();
		}
		return new ArrayList<Marca>();
	}
}
